package com.wwmz.pattern.prototype.deep;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wumz on 2020/9/17 16:37
 */
@Data
public class ConcreatePrototype implements Cloneable {

    private int sex;
    private String name;
    List<String> hobbies;

    @Override
    public ConcreatePrototype clone() {
        try {
            return (ConcreatePrototype)super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }

    public ConcreatePrototype deepCloneHobbies() {
        try {
            ConcreatePrototype result = (ConcreatePrototype) super.clone();
            result.hobbies = (List)((ArrayList)result.hobbies).clone();
            return result;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
